package com.minimalist.basic.controller.lindi;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.indexchangerecord.LindiIndexChangeRecordQueryVO;
import com.minimalist.common.entity.lindi.vo.indexchangerecord.LindiIndexChangeRecordVO;
import com.minimalist.common.feign.client.lindi.LindiIndexChangeRecordFeignClient;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * 林地指标交易平台_指标变更记录控制器
 *
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_指标变更记录管理")
@RequestMapping("/basic/lindi/indexChangeRecord")
public class LindiIndexChangeRecordController{

    @Autowired
    private LindiIndexChangeRecordFeignClient feignClient;

    @PostMapping("/addIndexChangeRecord")
    @Operation(summary = "添加指标变更记录")
    @SaCheckPermission("lindi:indexChangeRecord:add")
    public R<?> addIndexChangeRecord(
            @RequestBody @Validated(Add.class) LindiIndexChangeRecordVO recordVO){
        recordVO.setCreateId(StpUtil.getLoginIdAsLong());
        recordVO.setUpdateId(StpUtil.getLoginIdAsLong());
        LocalDateTime now = LocalDateTime.now();
        recordVO.setCreateTime(now);
        recordVO.setUpdateTime(now);
        return feignClient.addIndexChangeRecord(recordVO);
    }

    @DeleteMapping("/deleteIndexChangeRecordByIndexChangeRecordId")
    @Operation(summary = "删除指标变更记录 -> 根据记录ID删除")
    @SaCheckPermission("lindi:indexChangeRecord:delete")
    public R<?> deleteIndexChangeRecordByIndexChangeRecordId(
            @RequestParam("indexChangeRecordId")
            @NotNull(message = "记录ID不能为空")
            @Parameter(name = "indexChangeRecordId", required = true, description = "记录ID")
            Long indexChangeRecordId){
        return feignClient.deleteIndexChangeRecordByIndexChangeRecordId(indexChangeRecordId);
    }

    @PutMapping("/updateIndexChangeRecordByIndexChangeRecordId")
    @Operation(summary = "修改指标变更记录")
    @SaCheckPermission("lindi:indexChangeRecord:update")
    public R<?> updateIndexChangeRecordByIndexChangeRecordId(
            @RequestBody @Validated(Update.class) LindiIndexChangeRecordVO recordVO){
        recordVO.setCreateId(StpUtil.getLoginIdAsLong());
        recordVO.setUpdateId(StpUtil.getLoginIdAsLong());
        LocalDateTime now = LocalDateTime.now();
        recordVO.setCreateTime(now);
        recordVO.setUpdateTime(now);
        return feignClient.updateIndexChangeRecordByIndexChangeRecordId(recordVO);
    }

    @GetMapping("/getPageIndexChangeRecordList")
    @Operation(summary = "查询指标变更记录列表(分页)")
    @SaCheckPermission("lindi:indexChangeRecord:get")
    public R<PageResp<LindiIndexChangeRecordVO>> getPageIndexChangeRecordList(
            LindiIndexChangeRecordQueryVO queryVO){
        return feignClient.getPageIndexChangeRecordList(queryVO);
    }

    @GetMapping("/getIndexChangeRecordByIndexChangeRecordId/{indexChangeRecordId}")
    @Operation(summary = "根据记录ID查询指标变更记录")
    @SaCheckPermission("lindi:indexChangeRecord:get")
    public R<LindiIndexChangeRecordVO> getIndexChangeRecordByIndexChangeRecordId(
            @PathVariable(value = "indexChangeRecordId")
            @NotNull(message = "记录ID不能为空")
            @Parameter(name = "indexChangeRecordId", description = "记录ID", required = true)
            Long indexChangeRecordId){
        return feignClient.getIndexChangeRecordByIndexChangeRecordId(indexChangeRecordId);
    }
}